package com.mouse.magent.proxy.service;

import com.mouse.magent.common.net.TcpClient;
import com.mouse.magent.common.util.PropUtil;
import com.mouse.magent.proxy.constant.ProxyCommand;
import com.mouse.magent.proxy.handler.ProxyClientHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

@Slf4j
public class Proxy {
    public void start() throws Exception {
        String ip = PropUtil.getValue("server.ip", "127.0.0.1");
        Integer port = Integer.valueOf(PropUtil.getValue("server.port", "10087"));
        Integer remotePort = Integer.valueOf(PropUtil.getValue("server.remote.port", "8888"));
        String serverSecret = PropUtil.getValue("server.secret", "893656121");
        TcpClient tcpClient = new TcpClient();
        tcpClient.connect(ip, port, new ProxyClientHandler(serverSecret, remotePort), () -> Arrays.asList(ProxyCommand.values()));
        log.info("connect server success,ip:{} port:{}", ip, port);
    }
}
